//! 解析字符串错误类型

use thiserror::Error;

/// 解析字符串错误枚举类型
///
/// 表明了解析出错的类型
#[derive(Debug, Clone, PartialEq)]

pub enum ParseType {
    Kind,
    Power,
    Color,
    Point,
    Gender,
}

impl std::fmt::Display for ParseType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "sgs_core::card::{}",
            match self {
                ParseType::Kind => "Kind",
                ParseType::Power => "Power",
                ParseType::Color => "Color",
                ParseType::Point => "Point",
                ParseType::Gender => "Gender",
            }
        )
    }
}

/// 字符串解析错误类型
#[derive(Debug, Clone, Error)]
#[error("unable to parse \"{}\" into type \"{}\"", .from_str , .parse_type)]
pub struct ParseStrError {
    from_str: String,
    parse_type: ParseType,
}

impl ParseStrError {
    /// 创建错误类型
    pub fn new<S: ToString>(parse_type: ParseType, s: S) -> Self {
        Self {
            parse_type,
            from_str: s.to_string(),
        }
    }
}
